/*
	@file: log/include/LogBuilder.h
	@author: Wolfhead
 */
#ifndef _LOG_LOG_BUILDER_H_
#define _LOG_LOG_BUILDER_H_

#include <boost/thread.hpp>
#include <boost/noncopyable.hpp>
#include "logger_creator/LoggerCreator.h"
#include "formatter_creator/FormatterCreator.h"
#include "LogOption.h"

namespace logger
{

class LogBuilder;


class LogBuilder
	: public boost::noncopyable
{
public:
	LogBuilder();

	int build_from_file(const std::string& filepath, const std::string& type);

	int register_logger_creator(
		const std::string& name,
		LoggerCreatorPtr creator_ptr
		);

	int register_formatter_creator(
		const std::string& name,
		FormatterCreatorPtr creator_ptr
		);

private:

	void initialize_creator();

	int load_dispatcher(boost::property_tree::ptree& setting);

	int load_runner(
		const std::string& name,
		boost::property_tree::ptree& setting);

	int load_option(
		boost::property_tree::ptree& setting,
		LogOption& option
		);

	LoggerPtr create_logger(boost::property_tree::ptree& setting);

	FormatterPtr create_formatter(boost::property_tree::ptree& setting);

	FormatterPtr create_linked_formatter(boost::property_tree::ptree& setting);

	boost::shared_mutex m_mutex;

	std::map<std::string, LoggerCreatorPtr> m_logger_creator;
	std::map<std::string, FormatterCreatorPtr> m_formatter_creator;
};

}//namespace logger

#endif // #ifndef _LOG_LOG_BUILDER_H_
